from trade import models

def reistered_info_option(id, type_n=1):
  """
  处理数据库抢注域名的信息
  :param nid: 域名的id编号
  :return:
  """
  id = str(id)
  db_domain_list= models.DomainList.objects.filter(id=id).first()
  domain_name  = db_domain_list.domain_name
  db_reistered = models.Registered.objects.filter(domain_name=domain_name).first()
  try:
    db_info_list = db_reistered.registered_info
    db_info_dic = eval(db_info_list)
    totle = len(db_info_dic)
    reistered_user_list = db_info_dic.keys()
    info_dic = db_info_dic
    max_info_user_price, name = 0, ''
    max_info = {}
    if totle > 0:
      for name_key in reistered_user_list:
        user_reistered_info = db_info_dic[name_key]
        if int(user_reistered_info.get('price')) > max_info_user_price:
          max_info_user_price,name = int(user_reistered_info.get('price')), name_key
      max_info = db_info_dic[name]
  except AttributeError:
    max_info, info_dic, totle = None, None,0
  if type_n == 1:
    return max_info, totle, domain_name
  elif type_n == 2:
    return info_dic
  else:
    return max_info, info_dic, totle